﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace WJ.Infrastructure.Cache
{
    public class MemoryCache : ICacheStrategy,ISingleInstance
    {
        static ConcurrentDictionary<string, object> dic = new ConcurrentDictionary<string, object>();

        public T GetOne<T>(string key)
        {
            object value;

            dic.TryGetValue(key, out value);

            return (T) value;
        }

        public void SetOne<T>(string key, T value, TimeSpan timeOut)
        {
            throw new NotImplementedException();
        }

        public void SetOne<T>(string key, T value)
        {
            dic.AddOrUpdate(key, value, (oldkey, oldvalue) => value);
        }

        public void SetRangToList(string key, List<string> value)
        {
            throw new NotImplementedException();
        }

        public void RemoveOne(string key)
        {
            throw new NotImplementedException();
        }

        public void SetList<T>(string key, List<T> value, Func<T, object> getItemKey)
        {
            dic.AddOrUpdate(key, value, (oldkey, oldvalue) => value);
        }

        public void RemoveOneByList<T>(string key, T value, Func<T, object> getItemKey)
        {
            throw new NotImplementedException();
        }

        public void SetOneByList<T>(string key, T value, Func<T, object> getItemKey)
        {
            throw new NotImplementedException();
        }

        public List<T> GetList<T>(string key)
        {
            object value;

            dic.TryGetValue(key, out value);

            return (List<T>) value;
        }

        public T GetOneByList<T>(string key, Guid id)
        {
            throw new NotImplementedException();
        }

        public void PushToList(string listId, string value)
        {
            throw new NotImplementedException();
        }

        public string PopFromList(string listId)
        {
            throw new NotImplementedException();
        }
    }
}